      FUNCTION VRG1(IP,IG)
C     'VRG1' IS A FUNCTION WHICH EVALUATES THE RELATIVE GRAVITATIONAL
C     POTENTIAL FOR THE SATELLITE.
C
C
      IMPLICIT REAL*8 (A-H,O-Z)
      REAL*8 IP,IG(3,3),IPRMG,J2,J3,J4,J22
C
      COMMON/CNBODY/ J2,J3,J4,J22,ZJ20,ZMU,WWO,FLAT,AEARTH
C
      COMMON/DEBUG3/ ISWTCH
C
      COMMON/VECTRS/ XSAT(3),XSATDT(3),AD(3)
C
      DIMENSION XS(3),XIG(3)
C
      RAD=0.0D0
      DO 10 I=1,3
   10 RAD=RAD + XSAT(I)*XSAT(I)
      X3RAD=XSAT(3)*XSAT(3)/RAD
      RAD=DSQRT(RAD)
C
      DO 20 I=1,3
   20 XS(I)=XSAT(I)/RAD
C
      XSIG=0.0D0
      DO 30 I=1,3
   30 XSIG=XSIG + XS(I)*IG(I,3)
C
      DO 40 I=1,3
      XIG(I)=0.0D0
      DO 40 J=1,3
   40 XIG(I)=XIG(I) + XS(J)*IG(J,I)
C
      IPRMG=0.0D0
      DO 50 I=1,3
   50 IPRMG=IPRMG + XIG(I)*XS(I)
C
      RADSQR=RAD*RAD
      RADCBE=RAD*RADSQR
      ASQR=AEARTH*AEARTH
C
      Z2O=ZJ20*ASQR/RADSQR
      ZM3=ZMU/RADCBE
C
      VRG1=ZM3/2.D0*IP*(1.D0 + 1.5D0*Z2O - 7.5D0*Z2O*X3RAD)
     .    -1.5D0*ZM3*IPRMG*(1.D0 + 2.5D0*Z2O - 17.5D0*Z2O*X3RAD)
     .    +1.5D0*ZM3*Z2O*IG(3,3) - 1.5D1*ZM3*Z2O*XS(3)*XSIG
C
      IF(ISWTCH.NE.0) RETURN
      WRITE(6,10000) X3RAD,RAD,IPRMG,RADSQR,RADCBE,ASQR,Z2O,ZM3,XSIG
      WRITE(6,10001)
      WRITE(6,10002) (XS(I),I=1,3)
       WRITE(6,10003)
      WRITE(6,10002) (XIG(I),I=1,3)
      RETURN
C
10000 FORMAT('0',3X,'X3RAD ',G20.13,2X,'RAD ',G20.13,2X,'IPRMG ',G20.13/
     .           3X,'RADSQR ',G20.13,2X,'RADCBE ',G20.13,2X,'ASQR ',
     .           G20.13,2X/3X,'Z2O ',G20.13,2X,'ZM3 ',G20.13,2X,'XSIG ',
     .           G20.13)
10001 FORMAT('0',3X,'XS')
10002 FORMAT('0',3X,3(G20.13,2X))
10003 FORMAT('0',3X,'XIG')
C
      END
